package cn.com.oceansoft.business.mobile.danger.controller;

import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.base.entity.Result;
import cn.com.oceansoft.business.mobile.danger.entity.*;
import cn.com.oceansoft.business.mobile.danger.service.ICollecterService;
import cn.com.oceansoft.business.mobile.danger.service.IDnagerContentService;
import cn.com.oceansoft.business.mobile.danger.util.PicFkThread;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * 采集员
 * Created by zhangxl on 2018/4/27.
 */

@Controller
@RequestMapping("/api/collecter")
public class CollecterController {

    @Resource
    private ICollecterService collecterService;
    @Resource
    private IDnagerContentService dnagerContentService;

    /**
     * 用户注册页面
     * @return
     */
    @RequestMapping(value = "collecterInfo")
    public String collecterInfo(HttpServletRequest request,Model model){
        Object obj = request.getSession().getAttribute("openId");
        CollecterInfo collecterInfo = collecterService.findByOpenid(obj.toString());
        if(collecterInfo!=null){
            String role = collecterInfo.getRole().replace(",","");
            if(role.length()>1){
                model.addAttribute("disable","1");
            }
            model.addAttribute("collecterInfo",collecterInfo);
        }
        return "mobile/danger/collecterInfo";
    }

    /**
     * 上报列表页面
     * @return
     */
    @RequestMapping(value = "reportResult")
    public String reportResult(HttpServletRequest request, Model model,Query query){
        model.addAttribute("openId",request.getSession().getAttribute("openId"));
        return "mobile/danger/reportResultList";
    }

    /**
     * 反馈列表页面
     * @return
     */
    @RequestMapping(value = "listFK")
    public String listFK(HttpServletRequest request, Model model,Query query){
        CollecterInfo collecterInfo = collecterService.findByOpenid((String) request.getSession().getAttribute("openId"));
        if(collecterInfo !=null){
            if(collecterInfo.getRole()!=null){
                if(collecterInfo.getRole().indexOf("2")!=-1){//2：反馈员
                    model.addAttribute("openId",collecterInfo.getOpenid());
                    model.addAttribute("roletype",collecterInfo.getRoletype());
                    model.addAttribute("sqid",collecterInfo.getSqid());
                    model.addAttribute("pcsid",collecterInfo.getPcsid());
                }else{
                    model.addAttribute("nopower","1");
                }
            }else {
                model.addAttribute("nopower","1");
            }
        }else {
            model.addAttribute("nopower","1");
        }
        return "mobile/danger/listFK";
    }

    /**
     * 审批列表页面
     * @return
     */
    @RequestMapping(value = "listSP")
    public String listSP(HttpServletRequest request, Model model,Query query){
        CollecterInfo collecterInfo = collecterService.findByOpenid((String) request.getSession().getAttribute("openId"));
        if(collecterInfo !=null){
            if(collecterInfo.getRole()!=null){
                if(collecterInfo.getRole().indexOf("1")!=-1){//1：审核员
                    model.addAttribute("openId",collecterInfo.getOpenid());
                    model.addAttribute("roletype",collecterInfo.getRoletype());
                    model.addAttribute("sqid",collecterInfo.getSqid());
                    model.addAttribute("pcsid",collecterInfo.getPcsid());
                }else{//3.采集员
                    model.addAttribute("nopower","1");
                }
            }else {
                model.addAttribute("nopower","1");
            }
        }else {
            model.addAttribute("nopower","1");
        }
        return "mobile/danger/listSP";
    }

    /**
     * 上报详情页面
     * @return
     */
    @RequestMapping(value = "detail")
    public String detail(HttpServletRequest request, Model model){
        String id =  request.getParameter("id");
        DangerContent dc = collecterService.getDangerContentById(id);
        String address =dc.getFulladdress();
        String[] add =address.split("-");
        dc.setFjidname(add[0]);
        dc.setPcsidname(add[1]);
        dc.setSqidname(add[2]);
        String[] types = dc.getChildtype().split(",");
        String type ="";
        for(int i=0;i<types.length;i++){
            type +="☑ "+ collecterService.getYHByCode(types[i])+"</br>";
        }
        dc.setChildtype(type);
        FlowInfo flowInfo = collecterService.getDangerContentByIdTime(id);
        if("5".equals(flowInfo.getOpertype())){
            model.addAttribute("fkstatus","1");
        }
        if("9".equals(flowInfo.getOpertype())){
            model.addAttribute("thstatus","1");
        }
        if("4".equals(flowInfo.getOpertype())){
            model.addAttribute("clstatus","1");
        }
        if("6".equals(flowInfo.getOpertype())){//已反馈
            if(flowInfo.getIspenalty().equals("1")){
                Cfcs cfcs=collecterService.getCfcs(flowInfo.getId());
                if(cfcs!=null){
                    if(!"".equals(cfcs.getCflx())&&null!=cfcs.getCflx()){
                        String[]  cflx=cfcs.getCflx().split(",");
                        String nr ="";
                        for(int i=0;i<cflx.length;i++){
                            if(cflx[i].equals("1")){
                                nr +="☑ 警告&nbsp;&nbsp;";
                            }
                            if(cflx[i].equals("2")){
                                nr +="☑ 行政处罚&nbsp;&nbsp;";
                            }
                            if(cflx[i].equals("2")){
                                nr +="☑ 刑事强制措施";
                            }

                        }
                        cfcs.setCflx(nr);
                    }
                    if(!"".equals(cfcs.getCffs())&&null!=cfcs.getCffs()){
                        String[]  cffs=cfcs.getCffs().split(",");
                        String nr ="";
                        for(int i=0;i<cffs.length;i++){
                            if(cffs[i].equals("1")){
                                nr +="☑ 罚款&nbsp;&nbsp;";
                            }
                            if(cffs[i].equals("2")){
                                nr +="☑ 拘留";
                            }

                        }
                        cfcs.setCffs(nr);
                    }
                    if(!"".equals(cfcs.getXsqzcs())&&null!=cfcs.getXsqzcs()){
                        String[]  xsqzcs=cfcs.getXsqzcs().split(",");
                        String nr ="";
                        for(int i=0;i<xsqzcs.length;i++){
                            if(xsqzcs[i].equals("1")){
                                nr +="☑ 刑事拘留&nbsp;&nbsp;";
                            }
                            if(xsqzcs[i].equals("2")){
                                nr +="☑ 取保侯审";
                            }

                        }
                        cfcs.setXsqzcs(nr);
                    }
                    model.addAttribute("cfcs",cfcs);
                }

            }
            if(flowInfo.getIschange().equals("1")){
                Zgcs zgcs=collecterService.getZgcs(flowInfo.getId());
                model.addAttribute("zgcs",zgcs);
                model.addAttribute("photo1",collecterService.getPhotoBytypeAndId("3",flowInfo.getId()));
                model.addAttribute("photo2",collecterService.getPhotoBytypeAndId("4",flowInfo.getId()));
                model.addAttribute("photo3",collecterService.getPhotoBytypeAndId("5",flowInfo.getId()));
                model.addAttribute("photo4",collecterService.getPhotoBytypeAndId("6",flowInfo.getId()));
                model.addAttribute("photo5",collecterService.getPhotoBytypeAndId("7",flowInfo.getId()));
                model.addAttribute("photo6",collecterService.getPhotoBytypeAndId("8",flowInfo.getId()));
                model.addAttribute("photo7",collecterService.getPhotoBytypeAndId("9",flowInfo.getId()));
                model.addAttribute("photo8",collecterService.getPhotoBytypeAndId("10",flowInfo.getId()));
                model.addAttribute("photo9",collecterService.getPhotoBytypeAndId("11",flowInfo.getId()));
            }
        }
        if("8".equals(flowInfo.getOpertype())||"5".equals(flowInfo.getOpertype())||"7".equals(flowInfo.getOpertype())){//已反馈
            FlowInfo flow = collecterService.getYFkDetail(id);
            if(flow.getIspenalty().equals("1")){
                Cfcs cfcs=collecterService.getCfcs(flow.getId());
                if(cfcs!=null){
                    if(!"".equals(cfcs.getCflx())&&null!=cfcs.getCflx()){
                        String[]  cflx=cfcs.getCflx().split(",");
                        String nr ="";
                        for(int i=0;i<cflx.length;i++){
                            if(cflx[i].equals("1")){
                                nr +="☑ 警告&nbsp;&nbsp;";
                            }
                            if(cflx[i].equals("2")){
                                nr +="☑ 行政处罚&nbsp;&nbsp;";
                            }
                            if(cflx[i].equals("2")){
                                nr +="☑ 刑事强制措施";
                            }

                        }
                        cfcs.setCflx(nr);
                    }
                    if(!"".equals(cfcs.getCffs())&&null!=cfcs.getCffs()){
                        String[]  cffs=cfcs.getCffs().split(",");
                        String nr ="";
                        for(int i=0;i<cffs.length;i++){
                            if(cffs[i].equals("1")){
                                nr +="☑ 罚款&nbsp;&nbsp;";
                            }
                            if(cffs[i].equals("2")){
                                nr +="☑ 拘留";
                            }

                        }
                        cfcs.setCffs(nr);
                    }
                    if(!"".equals(cfcs.getXsqzcs())&&null!=cfcs.getXsqzcs()){
                        String[]  xsqzcs=cfcs.getXsqzcs().split(",");
                        String nr ="";
                        for(int i=0;i<xsqzcs.length;i++){
                            if(xsqzcs[i].equals("1")){
                                nr +="☑ 刑事拘留&nbsp;&nbsp;";
                            }
                            if(xsqzcs[i].equals("2")){
                                nr +="☑ 取保侯审";
                            }

                        }
                        cfcs.setXsqzcs(nr);
                    }
                    model.addAttribute("cfcs",cfcs);
                }

            }
            if(flow.getIschange().equals("1")){
                Zgcs zgcs=collecterService.getZgcs(flow.getId());
                model.addAttribute("zgcs",zgcs);
                model.addAttribute("photo1",collecterService.getPhotoBytypeAndId("3",flow.getId()));
                model.addAttribute("photo2",collecterService.getPhotoBytypeAndId("4",flow.getId()));
                model.addAttribute("photo3",collecterService.getPhotoBytypeAndId("5",flow.getId()));
                model.addAttribute("photo4",collecterService.getPhotoBytypeAndId("6",flow.getId()));
                model.addAttribute("photo5",collecterService.getPhotoBytypeAndId("7",flow.getId()));
                model.addAttribute("photo6",collecterService.getPhotoBytypeAndId("8",flow.getId()));
                model.addAttribute("photo7",collecterService.getPhotoBytypeAndId("9",flow.getId()));
                model.addAttribute("photo8",collecterService.getPhotoBytypeAndId("10",flow.getId()));
                model.addAttribute("photo9",collecterService.getPhotoBytypeAndId("11",flow.getId()));
            }
        }
        List<Map<String,Object>> list = collecterService.getPhotoByDCId(id);
        if("8".equals(flowInfo.getOpertype())||"5".equals(flowInfo.getOpertype())||"7".equals(flowInfo.getOpertype())){
            FlowInfo flowInfo2 = collecterService.getYFkDetail(id);
            List<Map<String,Object>> list2 = collecterService.getPhotoFKByDCId(flowInfo2.getId());
            model.addAttribute("photoF",list2);
        }else{
            List<Map<String,Object>> list2 = collecterService.getPhotoFKByDCId(flowInfo.getId());
            model.addAttribute("photoF",list2);
        }

        model.addAttribute("dangercontent",dc);
        model.addAttribute("flowInfo",flowInfo);
        model.addAttribute("photo",list);

        return "mobile/danger/detail";
    }


    /**
     * 未处理详情页
     * @return
     */
    @RequestMapping(value = "dealdetail")
    public String dealdetail(HttpServletRequest request, Model model){
        String id =  request.getParameter("id");
        DangerContent dc = collecterService.getDangerContentById(id);
        String address =dc.getFulladdress();
        String[] add =address.split("-");
        dc.setFjidname(add[0]);
        dc.setPcsidname(add[1]);
        dc.setSqidname(add[2]);
        String[] types = dc.getChildtype().split(",");
        String type ="";
        for(int i=0;i<types.length;i++){
            type +="☑ "+ collecterService.getYHByCode(types[i])+"</br>";
        }
        dc.setChildtype(type);
        List<Map<String,Object>> list = collecterService.getPhotoByDCId(id);
        model.addAttribute("dangercontent",dc);
        model.addAttribute("photo",list);
        return "mobile/danger/dealdetail";
    }


    /**
     * 已处理详情页
     * @return
     */
    @RequestMapping(value = "dealYdetail")
    public String dealYdetail(HttpServletRequest request, Model model){
        String id =  request.getParameter("id");
        DangerContent dc = collecterService.getDangerContentById(id);
        String address =dc.getFulladdress();
        String[] add =address.split("-");
        dc.setFjidname(add[0]);
        dc.setPcsidname(add[1]);
        dc.setSqidname(add[2]);
        String[] types = dc.getChildtype().split(",");
        String type ="";
        for(int i=0;i<types.length;i++){
            type +="☑ "+ collecterService.getYHByCode(types[i])+"</br>";
        }
        dc.setChildtype(type);
        FlowInfo flowInfo = collecterService.getDangerContentByIdTime(id);
        List<Map<String,Object>> list = collecterService.getPhotoByDCId(id);
        model.addAttribute("dangercontent",dc);
        model.addAttribute("flowInfo",flowInfo);
        model.addAttribute("photo",list);
        return "mobile/danger/dealYdetail";
    }

    /**
     * 未反馈详情页
     * @return
     */
    @RequestMapping(value = "dealYFdetail")
    public String dealYFdetail(HttpServletRequest request, Model model){
        String id =  request.getParameter("id");
        DangerContent dc = collecterService.getDangerContentById(id);
        FlowInfo flowInfo = collecterService.getDangerContentByIdTime(id);
        String address =dc.getFulladdress();
        String[] add =address.split("-");
        dc.setFjidname(add[0]);
        dc.setPcsidname(add[1]);
        dc.setSqidname(add[2]);
        String[] types = dc.getChildtype().split(",");
        String type ="";
        for(int i=0;i<types.length;i++){
            type +="☑ "+ collecterService.getYHByCode(types[i])+"</br>";
        }
        dc.setChildtype(type);
        List<Map<String,Object>> list = collecterService.getPhotoByDCId(id);
        model.addAttribute("dangercontent",dc);
        model.addAttribute("flowInfo",flowInfo);
        model.addAttribute("photo",list);
        if(flowInfo.getOpertype().equals("8")){
            FlowInfo flowInfo2 = collecterService.getYFkDetail(id);
            List<Map<String,Object>> list2 = collecterService.getPhotoFKByDCId(flowInfo2.getId());
            model.addAttribute("photoF",list2);
            model.addAttribute("size",list2.size());
        }
        return "mobile/danger/dealYFdetail";
    }

    /**
     * 已反馈详情页
     * @return
     */
    @RequestMapping(value = "dealYFFdetail")
    public String dealYFFdetail(HttpServletRequest request, Model model){
        String id =  request.getParameter("id");
        DangerContent dc = collecterService.getDangerContentById(id);
        String address =dc.getFulladdress();
        String[] add =address.split("-");
        dc.setFjidname(add[0]);
        dc.setPcsidname(add[1]);
        dc.setSqidname(add[2]);
        String[] types = dc.getChildtype().split(",");
        String type ="";
        for(int i=0;i<types.length;i++){
            type +="☑ "+ collecterService.getYHByCode(types[i])+"</br>";
        }
        dc.setChildtype(type);
        FlowInfo flowInfo = collecterService.getYFkDetail(id);
        if(flowInfo.getIspenalty().equals("1")){
            Cfcs cfcs=collecterService.getCfcs(flowInfo.getId());
            if(cfcs!=null){
                if(!"".equals(cfcs.getCflx())&&null!=cfcs.getCflx()){
                    String[]  cflx=cfcs.getCflx().split(",");
                    String nr ="";
                    for(int i=0;i<cflx.length;i++){
                        if(cflx[i].equals("1")){
                            nr +="☑ 警告&nbsp;&nbsp;";
                        }
                        if(cflx[i].equals("2")){
                            nr +="☑ 行政处罚&nbsp;&nbsp;";
                        }
                        if(cflx[i].equals("2")){
                            nr +="☑ 刑事强制措施";
                        }

                    }
                    cfcs.setCflx(nr);
                }
                if(!"".equals(cfcs.getCffs())&&null!=cfcs.getCffs()){
                    String[]  cffs=cfcs.getCffs().split(",");
                    String nr ="";
                    for(int i=0;i<cffs.length;i++){
                        if(cffs[i].equals("1")){
                            nr +="☑ 罚款&nbsp;&nbsp;";
                        }
                        if(cffs[i].equals("2")){
                            nr +="☑ 拘留";
                        }

                    }
                    cfcs.setCffs(nr);
                }
                if(!"".equals(cfcs.getXsqzcs())&&null!=cfcs.getXsqzcs()){
                    String[]  xsqzcs=cfcs.getXsqzcs().split(",");
                    String nr ="";
                    for(int i=0;i<xsqzcs.length;i++){
                        if(xsqzcs[i].equals("1")){
                            nr +="☑ 刑事拘留&nbsp;&nbsp;";
                        }
                        if(xsqzcs[i].equals("2")){
                            nr +="☑ 取保侯审";
                        }

                    }
                    cfcs.setXsqzcs(nr);
                }
                model.addAttribute("cfcs",cfcs);
            }

        }
        if(flowInfo.getIschange().equals("1")){
            Zgcs zgcs=collecterService.getZgcs(flowInfo.getId());
            model.addAttribute("zgcs",zgcs);
            model.addAttribute("photo1",collecterService.getPhotoBytypeAndId("3",flowInfo.getId()));
            model.addAttribute("photo2",collecterService.getPhotoBytypeAndId("4",flowInfo.getId()));
            model.addAttribute("photo3",collecterService.getPhotoBytypeAndId("5",flowInfo.getId()));
            model.addAttribute("photo4",collecterService.getPhotoBytypeAndId("6",flowInfo.getId()));
            model.addAttribute("photo5",collecterService.getPhotoBytypeAndId("7",flowInfo.getId()));
            model.addAttribute("photo6",collecterService.getPhotoBytypeAndId("8",flowInfo.getId()));
            model.addAttribute("photo7",collecterService.getPhotoBytypeAndId("9",flowInfo.getId()));
            model.addAttribute("photo8",collecterService.getPhotoBytypeAndId("10",flowInfo.getId()));
            model.addAttribute("photo9",collecterService.getPhotoBytypeAndId("11",flowInfo.getId()));
        }
        List<Map<String,Object>> list = collecterService.getPhotoByDCId(id);
        List<Map<String,Object>> list2 = collecterService.getPhotoFKByDCId(flowInfo.getId());
        model.addAttribute("dangercontent",dc);
        model.addAttribute("flowInfo",flowInfo);
        model.addAttribute("photo",list);
        model.addAttribute("photoF",list2);
        return "mobile/danger/dealYFFdetail";
    }


    /**
     * 注册采集员
     */
    @ResponseBody
    @RequestMapping(value = "collecterInfoSubmit", method = RequestMethod.POST)
    public Result collecterInfoSubmit(HttpServletRequest request, CollecterInfo collecterInfo) {
        collecterInfo.setCreatetime(new Date());
        collecterInfo.setUpdatetime(new Date());
        collecterInfo.setOpenid((String) request.getSession().getAttribute("openId"));
        collecterInfo.setStatus("0");
        collecterInfo.setDelflag("0");
        collecterInfo.setRole("3");
        return collecterService.collecterInfoSubmit(collecterInfo);
    }

    /**
     * 所属区
     */
    @ResponseBody
    @RequestMapping(value = "getSsq")
    public Result getSsq(HttpServletRequest request) {
        //List<Map<String,Object>> list = (List<Map<String,Object>>)CacheBaseService.getInstance().getObject("sqxx_fjlist");
        //JSONArray list= DictUtil.getChildByParentid("C7",1);getfjList
        //JSONArray list= DictUtil.getfjList();
        JSONArray list= dnagerContentService.getfjList();
        Result result = new Result();
        result.setData(list);
        return  result;
    }

    /**
     * 街道
     */
    @ResponseBody
    @RequestMapping(value = "getJd")
    public Result getJd(HttpServletRequest request) {
        //JSONArray list= DictUtil.getChildByParentid(request.getParameter("fjid"),1);
        JSONArray list= dnagerContentService.getChildByParentid(request.getParameter("fjid"),1);
        Result result = new Result();
        result.setData(list);
        return  result;
    }

    /**
     * 社区
     */
    @ResponseBody
    @RequestMapping(value = "getSq")
    public Result getSq(HttpServletRequest request) {
        //JSONArray list= DictUtil.getChildByParentid(request.getParameter("pcsid"),2);
        JSONArray list= dnagerContentService.getChildByParentid(request.getParameter("pcsid"),2);
       // list.add(0,DictUtil.getObjectById(request.getParameter("pcsid")));
        list.add(0,dnagerContentService.getObjectById(request.getParameter("pcsid")));
        Result result = new Result();
        result.setData(list);
        return  result;
    }

    /**
     * 上报列表获取
     */
    @ResponseBody
    @RequestMapping(value = "reportResult/page", method = POST)
    public Result loadReportResultByPage(HttpServletRequest request, Query query){
        query.setNumPerPage(10);
        Map<String, String> map = new HashMap<>();
        map.put("openId",(String)request.getSession().getAttribute("openId"));
//        map.put("openId",request.getParameter("openId"));
        query.setMap(map);
        Pager<DangerContent> pager = collecterService.loadReportResultByPage(query);
        Result result = new Result();
        result.setData(pager);
        return result;
    }

    /**
     * 未处理列表获取
     */
    @ResponseBody
    @RequestMapping(value = "listpage/wcl", method = POST)
    public Result loadListWclByPage(HttpServletRequest request, Query query){
        query.setNumPerPage(10);
        Map<String, String> map = new HashMap<>();
        map.put("openId",(String)request.getSession().getAttribute("openId"));
//        map.put("openId",request.getParameter("openId"));
        map.put("roletype",request.getParameter("roletype"));
        map.put("sqid",request.getParameter("sqid"));
        map.put("pcsid",request.getParameter("pcsid"));
        String type = request.getParameter("type");
        if(type!=null&&type.equals("0")){
            type = "";
        }
        map.put("type",type);
        map.put("fullAddress",request.getParameter("fullAddress"));
        query.setMap(map);
        Pager<DangerContent> pager = collecterService.loadListWByPage(query);
        Result result = new Result();
        result.setData(pager);
        return result;
    }

    /**
     * 已处理列表获取
     */
    @ResponseBody
    @RequestMapping(value = "listpage/ycl", method = POST)
    public Result loadListYclByPage(HttpServletRequest request, Query query){
        query.setNumPerPage(10);
        Map<String, String> map = new HashMap<>();
        map.put("openId",(String)request.getSession().getAttribute("openId"));
//        map.put("openId",request.getParameter("openId"));
        map.put("roletype",request.getParameter("roletype"));
        map.put("sqid",request.getParameter("sqid"));
        map.put("pcsid",request.getParameter("pcsid"));
        String type = request.getParameter("type");
        if(type!=null&&type.equals("0")){
            type = "";
        }
        map.put("type",type);
        map.put("fullAddress",request.getParameter("fullAddress"));
        query.setMap(map);
        Pager<DangerContent> pager = collecterService.loadListYByPage(query);
        Result result = new Result();
        result.setData(pager);
        return result;
    }

    /**
     * 未反馈列表获取
     */
    @ResponseBody
    @RequestMapping(value = "listFpage/wcl", method = POST)
    public Result loadListWclFByPage(HttpServletRequest request, Query query){
        query.setNumPerPage(10);
        Map<String, String> map = new HashMap<>();
        map.put("openId",(String)request.getSession().getAttribute("openId"));
//        map.put("openId",request.getParameter("openId"));
        map.put("roletype",request.getParameter("roletype"));
        map.put("sqid",request.getParameter("sqid"));
        map.put("pcsid",request.getParameter("pcsid"));
        String type = request.getParameter("type");
        if(type!=null&&type.equals("0")){
            type = "";
        }
        map.put("type",type);
        map.put("fullAddress",request.getParameter("fullAddress"));
        query.setMap(map);
        Pager<DangerContent> pager = collecterService.loadListWFByPage(query);
        Result result = new Result();
        result.setData(pager);
        return result;
    }

    /**
     * 已反馈列表获取
     */
    @ResponseBody
    @RequestMapping(value = "listFpage/ycl", method = POST)
    public Result loadListYclFByPage(HttpServletRequest request, Query query){
        query.setNumPerPage(10);
        Map<String, String> map = new HashMap<>();
        map.put("openId",(String)request.getSession().getAttribute("openId"));
//        map.put("openId",request.getParameter("openId"));
        map.put("roletype",request.getParameter("roletype"));
        map.put("sqid",request.getParameter("sqid"));
        map.put("pcsid",request.getParameter("pcsid"));
        String type = request.getParameter("type");
        if(type!=null&&type.equals("0")){
            type = "";
        }
        map.put("type",type);
        map.put("fullAddress",request.getParameter("fullAddress"));
        query.setMap(map);
        Pager<DangerContent> pager = collecterService.loadListYFByPage(query);
        Result result = new Result();
        result.setData(pager);
        return result;
    }

    /**
     * 处理
     */
    @ResponseBody
    @RequestMapping(value = "clForm", method = RequestMethod.POST)
    public Result clForm(HttpServletRequest request, FlowInfo flowInfo) {
        flowInfo.setCreatetime(new Date());
        flowInfo.setDealresult("1");
//        if("1".equals(flowInfo.getIschange())){
        flowInfo.setOpertype("4");
//        }else{
//            flowInfo.setOpertype("3");
//        }
        flowInfo.setCollecterid((String) request.getSession().getAttribute("openId"));
        return collecterService.insertFlowInfo(flowInfo);
    }

    /**
     * 流转
     */
    @ResponseBody
    @RequestMapping(value = "lzForm", method = RequestMethod.POST)
    public Result lzForm(HttpServletRequest request, FlowInfo flowInfo) {
        flowInfo.setCreatetime(new Date());
        flowInfo.setDealresult("1");
        flowInfo.setOpertype("2");
        flowInfo.setCollecterid((String) request.getSession().getAttribute("openId"));
        return collecterService.insertFlowInfo(flowInfo);
    }

    /**
     * 退回
     */
    @ResponseBody
    @RequestMapping(value = "thForm", method = RequestMethod.POST)
    public Result thForm(HttpServletRequest request, FlowInfo flowInfo) {
        flowInfo.setCreatetime(new Date());
        flowInfo.setOpertype("9");
        flowInfo.setCollecterid((String) request.getSession().getAttribute("openId"));
        return collecterService.insertFlowInfo(flowInfo);
    }

    /**
     * 反馈
     */
    @ResponseBody
    @RequestMapping(value = "fkForm", method = RequestMethod.POST)
    public Result fkForm(HttpServletRequest request, FlowInfo flowInfo, Cfcs cfcs, Zgcs zgcs) {
        flowInfo.setCreatetime(new Date());
        flowInfo.setOpertype("6");//反馈待确认
        flowInfo.setCollecterid((String) request.getSession().getAttribute("openId"));
        /*DangerContent dc = new DangerContent();
        dc.setId(flowInfo.getDangerid());
        dc.setPhoto1(flowInfo.getDealphoto1());
        dc.setStatus("1");//上传图片来源反馈
        PicThread thread=new PicThread(dc,wechatService);
        thread.start();*/
//        PicFkThread thread=new PicFkThread(flowInfo,wechatService);
//        thread.start();
        Result result=collecterService.insertFlowInfo(flowInfo);
        if(result.getMsg().equals("提交成功!")){
            PicFkThread thread=new PicFkThread(flowInfo);
            thread.start();
            if(flowInfo.getIspenalty().equals("1")){
                cfcs.setIsdelete("0");
                cfcs.setFlowid(flowInfo.getId());
                if("".equals(cfcs.getFkje())){
                    cfcs.setFkje(null);
                }
                if("".equals(cfcs.getXzjlrs())){
                    cfcs.setXzjlrs(null);
                }
                if("".equals(cfcs.getXsjlrs())){
                    cfcs.setXsjlrs(null);
                }
                if("".equals(cfcs.getQbhsrs())){
                    cfcs.setQbhsrs(null);
                }
                if("".equals(cfcs.getJgrs())){
                    cfcs.setJgrs(null);
                }
                Result cf= collecterService.insertCfcs(cfcs);
            }
            if(flowInfo.getIschange().equals("1")){
                zgcs.setIsdelete("0");
                zgcs.setFlowid(flowInfo.getId());
                if("".equals(zgcs.getGlmj())){
                    zgcs.setGlmj(null);
                }
                if("".equals(zgcs.getZlmj())){
                    zgcs.setZlmj(null);
                }
                if("".equals(zgcs.getWjmj())){
                    zgcs.setWjmj(null);
                }
                if("".equals(zgcs.getLhzf())){
                    zgcs.setLhzf(null);
                }
                if("".equals(zgcs.getTytc())){
                    zgcs.setTytc(null);
                }
                if("".equals(zgcs.getTz())){
                    zgcs.setTz(null);
                }
                if("".equals(zgcs.getTstd())){
                    zgcs.setTstd(null);
                }
                if("".equals(zgcs.getZltzsy())){
                    zgcs.setZltzsy(null);
                }
                if("".equals(zgcs.getCf())){
                    zgcs.setCf(null);
                }
                if("".equals(zgcs.getBlwgjz())){
                    zgcs.setBlwgjz(null);
                }
                if("".equals(zgcs.getYtdsr())){
                    zgcs.setYtdsr(null);
                }
                Result zg= collecterService.insertZgcs(zgcs);
            }
        }

        return result;
    }
    @ResponseBody
    @RequestMapping(value = "deletepic")
    public Result deletepic(HttpServletRequest request) {
        String url=request.getParameter("url");
        return  collecterService.deletePic(url);
    }
}
